package com.edu.exam.enums;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 行政操作类型枚举
 * 
 * @author System
 * @version 1.0.0
 */
public enum OperationType implements BaseEnum {
    /**
     * 班级创建
     */
    CLASS_CREATE("ClassCreate", "班级创建"),
    
    /**
     * 班级更新
     */
    CLASS_UPDATE("ClassUpdate", "班级更新"),
    
    /**
     * 班级删除
     */
    CLASS_DELETE("ClassDelete", "班级删除"),
    
    /**
     * 班级状态变更
     */
    CLASS_STATUS_CHANGE("ClassStatusChange", "班级状态变更"),
    
    /**
     * 班级合并
     */
    CLASS_MERGE("ClassMerge", "班级合并"),
    
    /**
     * 班级拆分
     */
    CLASS_SPLIT("ClassSplit", "班级拆分"),
    
    /**
     * 学生分班
     */
    STUDENT_ASSIGN("StudentAssign", "学生分班"),
    
    /**
     * 学生转班
     */
    STUDENT_TRANSFER("StudentTransfer", "学生转班"),
    
    /**
     * 学生移出班级
     */
    STUDENT_REMOVE("StudentRemove", "学生移出班级"),
    
    /**
     * 批量分班
     */
    BATCH_ASSIGN("BatchAssign", "批量分班"),
    
    /**
     * 批量转班
     */
    BATCH_TRANSFER("BatchTransfer", "批量转班"),
    
    /**
     * 班主任分配
     */
    ADVISOR_ASSIGN("AdvisorAssign", "班主任分配"),
    
    /**
     * 班主任更换
     */
    ADVISOR_CHANGE("AdvisorChange", "班主任更换"),
    
    /**
     * 班级调整
     */
    CLASS_ADJUSTMENT("ClassAdjustment", "班级调整"),
    
    /**
     * 数据导入
     */
    DATA_IMPORT("DataImport", "数据导入"),
    
    /**
     * 数据导出
     */
    DATA_EXPORT("DataExport", "数据导出");

    private final String code;
    private final String description;

    OperationType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 获取显示名称（中文描述）
     * 
     * @return 中文显示名称
     */
    public String getDisplayName() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static OperationType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Operation type code cannot be null or empty");
        }

        for (OperationType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown operation type code: " + code);
    }

    /**
     * 根据描述获取枚举值
     *
     * @param description 描述
     * @return 枚举值，如果未找到返回null
     */
    public static OperationType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return null;
        }

        for (OperationType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}